
	** ETHIOPIA: CLEAN WAVE 4
		
	 * prep consumption file 
	 use "$dir/rawdata/LSMS Ethiopia/2018/cons_agg_w4.dta", clear
	 
	 ren nom_totcons_aeq w4_conspc
	 ren hh_size w4_hhsize_fromcons
	 
	 keep household_id w4*
	 tempfile consumption
	 save `consumption', replace
	 
	 use "$dir/rawdata/LSMS Ethiopia/2018/sect1_hh_w4.dta", clear // ROSTER
	 merge 1:1 household_id individual_id using "$dir/rawdata/LSMS Ethiopia/2018/sect3_hh_w4.dta", assert(master matched) nogen // HEALTH
	 merge 1:1 household_id individual_id using "$dir/rawdata/LSMS Ethiopia/2018/sect4_hh_w4.dta", assert(master matched) nogen // LABOR
	 merge m:1 household_id using `consumption', assert(master matched) nogen // CONSUMPTION
		 
		 /*
		 Section 1: Roster
		 Section 2: Education
		 Section 3: Health
		 Section 4: Time use and labor	 
		 Section 5a&b: Savings and financial assets
		 
		 Section 6a & 6b: Food
		 Section 7: Non-food expenditure
		 Section 8: Food security
		 Section 9: Shocks
		 Section 10a & 10b & 10c: Housing and land parcel & land
		 Section 11a & 11b: Assets and phone ownership
		 Section 12a & 12b: Non-farm enterprise
		 Section 13: Other income
		 Section 14: Assistance
		 Section 15: Credit
		 Section 10d & 10e: Large livestock roster
		 */
		 
	 ren household_id hhid
	 gen indiv=individual_id
	 destring indiv, replace
 
	 ** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
			gen w4_inhh=s1q05!=2
		
		** Age
			gen w4_age=s1q03a
			
		** Household size
			gen temp=1 if w4_inhh==1
			bys hhid: egen w4_hh_size=total(temp)
			drop temp

		** Number of children 12 or younger
			gen temp=1 if w4_age<=12 & w4_inhh==1
			bys hhid: egen w4_hh_under12=total(temp)
			drop temp

		** Number of youth 18 or younger
			gen temp=1 if w4_age<=18 & w4_inhh==1
			bys hhid: egen w4_hh_under18=total(temp)
			drop temp

		** Number of adults 60 or older
			gen temp=1 if w4_age>=60 & !missing(w4_age) & w4_age!=999 & w4_inhh==1
			bys hhid: egen w4_hh_over60=total(temp)
			drop temp

		** Adults 12 to 60
			gen temp=1 if w4_age>12 & w4_age<60 & !missing(w4_age) & w4_age!=999 & w4_inhh==1
			bys hhid: egen w4_hh_12to60=total(temp)
			drop temp

		** Marital status
			gen w4_married=(s1q09==2 | s1q09==3) if !missing(s1q09)
			gen w4_married_monog=(s1q09==2) if !missing(s1q09)
			gen w4_married_polyg=(s1q09==3) if !missing(s1q09)

		** Female
			gen w4_female=(s1q02==2) if !missing(s1q02)

		** Age of spouse
			sum indiv
			forvalues x=1/`r(max)' {
				gen age_person`x'_temp=w4_age if indiv==`x' & !missing(w4_age)
				bys hhid: egen age_person`x'=max(age_person`x'_temp)
				drop age_person`x'_temp
			}

		** Average age of others in the household
			sum indiv 
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if indiv==`x'
			}
			egen w4_hh_avgage=rowmean(age_person*)
			
		** Spouse age
			sum indiv
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if s1q11!=`x'
			}
			egen w4_spouse_age=rowmean(age_person*)

		** Age gap
			gen w4_spouse_agegap=w4_age-w4_spouse_age

		** Birthday
			gen w4_birthday=mdy(s3q34_b,s3q34_a,s3q34_c)
			format w4_birthday %td
			
		** Birth year
			gen w4_birthyear=s3q34_c
			recode w4_birthyear 9999=. 9998=.
			replace w4_birthyear=2015-w4_age if missing(w4_birthyear)
			
	***********
	***********
	
	** Geographic information
	
		gen w4_geo_urban=(saq14==2) if !missing(saq14)
		
	***********
	***********

	** LABOR

		** Worked for a non-HH member
			gen w4_work_outsideHH=(s4q10==1 | s4q12==1) if !missing(s4q10) | !missing(s4q12)
			egen w4_work_outsideHH_hrs=rowtotal(s4q11 s4q13), mi
			replace w4_work_outsideHH_hrs=0 if w4_work_outsideHH==0
			
		** Worked in agriculture for a HH member
			gen w4_work_agHH=s4q05==1 if !missing(s4q05)
			gen w4_work_agHH_hrs=s4q06
			replace w4_work_agHH_hrs=0 if w4_work_agHH==0
			
		** Worked in HH business
			gen w4_work_bizHH=s4q08==1 if !missing(s4q08)
			gen w4_work_bizHH_hrs=s4q09
			replace w4_work_bizHH_hrs=0 if w4_work_bizHH==0
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w4_worked_last7days=rowmax(w4_work_outsideHH w4_work_agHH w4_work_bizHH)
			
		** Hours worked in last 7 days
			egen w4_work_hrs=rowtotal(w4_work_outsideHH_hrs w4_work_agHH_hrs w4_work_bizHH_hrs)
			replace w4_work_hrs=. if missing(w4_work_outsideHH_hrs) & missing(w4_work_agHH_hrs) & missing(w4_work_bizHH_hrs)
				
		** Works in agriculture
			gen w4_work_agri=(s4q34d==1 | w4_work_agHH==1) if (!missing(s4q34d) | !missing(w4_work_agHH))
		
	***********
	***********

	** HEALTH
		
		** Any illness or injury during the last 4 weeks
			gen w4_ill_inj=(s3q05==1) if !missing(s3q05)

		** Had to stop usual activity in the past 4 weeks
			gen w4_ill_inj_stopactivity=(s3q07==1) if !missing(s3q07)
			replace w4_ill_inj_stopactivity=0 if w4_ill_inj==0

	***********
	***********

	** DISABILITIES

		** Difficulty seeing
			tab1 s3q21, nol
			tab1 s3q21
			gen w4_diff_seei=1 if inlist(s3q21, 2, 3, 4) 
			replace w4_diff_seei=0 if inlist(s3q21, 1)
			replace w4_diff_seei=. if inlist(s3q21, .)
			tab1 w4_diff_seei

		** Difficulty hearing
			tab1 s3q22, nol
			tab1 s3q22
			gen w4_diff_hear=1 if inlist(s3q22, 2, 3, 4) 
			replace w4_diff_hear=0 if inlist(s3q22, 1)
			replace w4_diff_hear=. if inlist(s3q22, .)
			tab1 w4_diff_hear

		** Difficulty walking or climbing stairs	
			tab1 s3q23, nol
			tab1 s3q23
			gen w4_diff_walk_clim=1 if inlist(s3q23, 2, 3, 4) 
			replace w4_diff_walk_clim=0 if inlist(s3q23, 1)
			replace w4_diff_walk_clim=. if inlist(s3q23, .)
			tab1 w4_diff_walk_clim

		** Difficulty remembering or concentrating
			tab1 s3q24, nol
			tab1 s3q24
			gen w4_diff_reme=1 if inlist(s3q24, 2, 3, 4) 
			replace w4_diff_reme=0 if inlist(s3q24,1)
			replace w4_diff_reme=. if inlist(s3q24, .)
			tab1 w4_diff_reme

		** Difficulty with self-care
			tab1 s3q25, nol
			tab1 s3q25
			gen w4_diff_self_care=1 if inlist(s3q25, 2, 3, 4)
			replace w4_diff_self_care=0 if inlist(s3q25, 1)
			replace w4_diff_self_care=. if inlist(s3q25, .)
			tab1 w4_diff_self_care

		** Difficulty communicating
			tab1 s3q26, nol
			tab1 s3q26
			gen w4_diff_comm=1 if inlist(s3q26, 2, 3, 4) 
			replace w4_diff_comm=0 if inlist(s3q26, 1)
			replace w4_diff_comm=. if inlist(s3q26, .)
			tab1 w4_diff_comm
			
	***********
	***********
	
	** SAVE
	
		keep hhid indiv w4*
		order hhid indiv w4*
		save "$dir/data/ETH_w4_individual.dta", replace
